import os
import time

class FileLog(object):
    def __init__(self, name):
        self.name = name

    def _log(self, msg):
        """
        log the message into file for troubleshooting purpose
        """
        try:
            file_handle = open(self.name, 'a')
        except:
            try:
                os.mkdir('%s%slogs' % (os.path.dirname(os.path.abspath(__file__)), os.sep))
                file_handle = open(self.name, 'a')
            except:
                raise Exception, 'open log file %s failed' % self.name

        try:
            file_handle.write('%s %s\n' % (time.ctime(), msg))
        finally:
            file_handle.close()